package org.example;

import org.example.protobuf.Example.Person;

import java.io.IOException;

//TIP 要<b>运行</b>代码，请按 <shortcut actionId="Run"/> 或
// 点击装订区域中的 <icon src="AllIcons.Actions.Execute"/> 图标。
public class SimpleReadAndWriteDemo {
    public static void main(String[] args) throws IOException {
        // 创建一个 Person 对象
        Person.Builder personBuilder = Person.newBuilder();
        personBuilder.setName("Alice");
        personBuilder.setAge(30);
        personBuilder.setEmail("alice@example.com");
        Person person = personBuilder.build();

        // 序列化对象
        byte[] serializedData = person.toByteArray();

        // 反序列化对象
        Person newPerson = Person.parseFrom(serializedData);

        // 打印反序列化后的对象
        System.out.println("Name: " + newPerson.getName());
        System.out.println("Age: " + newPerson.getAge());
        System.out.println("Email: " + newPerson.getEmail());
    }
}